using UnityEngine;

public class PlayerCatchSwordState : PlayerState
{
    private Transform sword;

    public PlayerCatchSwordState(Player player, string animBoolName) : base(player, animBoolName) { }

    public override void Enter()
    {
        base.Enter();
        sword = player.Sword.transform;
        player.Fx.PlayDustFx();
        player.Fx.ScreenShake(player.Fx.shakeSwordImpact);
        if (player.transform.position.x > sword.position.x && player.FacingDirection == 1)
        {
            player.Flip();
        }
        else if (player.transform.position.x < sword.position.x && player.FacingDirection == -1)
        {
            player.Flip();
        }
        rb.velocity = new(player.swordReturnImpact * -player.FacingDirection, rb.velocity.y);
    }

    public override void Exit()
    {
        base.Exit();
    }

    public override void Update()
    {
        base.Update();

        if (triggerCalled)
        {
            StateMachine.ChangeState(player.IdleState);
        }
    }
}
